#include "Program.h"

#include <compilation/task/DominationTask.h>


namespace compilation
{


void
Program::computeDominators(void)
{
  UNSET_DEBUG_FOR_VISITORS();

  if (debug_instruction_visitor)
    std::cout
        << "computeDominators:\n"
           "------------------\n";

  DominationAgenda::instruction_handler_visitor_type dhv =
      DominationAgenda::instruction_handler_visitor_type
      ::build_visitor<DominationHandler>();

  DominationAgenda::instruction_propagator_visitor_type dpv =
      DominationAgenda::instruction_propagator_visitor_type
      ::build_visitor<DefaultInstructionPropagator
      <DominationTask, DominationAgenda>::type>();

  for (std::set<Function>::const_iterator functionIter = m_functions.begin();
       functionIter != m_functions.end(); ++functionIter)
  {
    DominationAgenda agenda(dhv, dpv, *functionIter);
    execute(agenda);
  }
}


void
Program::computeDominationFrontiers(void)
{
  for (std::set<Function>::iterator functionIter =
       m_functions.begin();
       functionIter != m_functions.end();
       ++functionIter)
    const_cast<Function&>(*functionIter).setDominationFrontier();
}


} // compilation
